package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.briup.jz.bean.AccountCustomer;
import com.briup.jz.bean.AccountCustomerExample;
import com.briup.jz.bean.AccountCustomerExample.Criteria;
import com.briup.jz.dao.AccountApplyMapper;
import com.briup.jz.dao.AccountCustomerMapper;
import com.briup.jz.service.IAccountCustomerService;
import com.briup.jz.utils.CustomerException;
@Service
public class AccountCustomerlmpl implements IAccountCustomerService {
	@Autowired
	AccountCustomerMapper accountMaaper;
	
	@Override
	public void saveOrUpdate(AccountCustomer account) throws CustomerException {
		// TODO Auto-generated method stub
		if(account.getId()!=null) {
			accountMaaper.updateByPrimaryKey(account);
		} else {
			accountMaaper.insert(account);
		}
	}

	@Override
	public List<AccountCustomer> query(Long userId) {
		// TODO Auto-generated method stub
		AccountCustomerExample example = new AccountCustomerExample();
		if(userId!=null)
		{
			example.createCriteria().andUserIdEqualTo(userId);
		}
	return accountMaaper.selectByExample(example);
	}

	@Override
	public void deleteById(long id) throws CustomerException {
		// TODO Auto-generated method stub
		AccountCustomer accountCustomer= accountMaaper.selectByPrimaryKey(id);
		if(accountCustomer!=null)
		{
			accountMaaper.deleteByPrimaryKey(id);
		}else {
		throw new CustomerException("要删除的分类信息不存在");
		}
	}


}
